package site.xuxingcan.wifihost;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

/**
 * Created by xuxingcan on 16-10-24.
 */
public class FileUtil {

    //写数据到SD中的文件
    public static void writeFileSdcardFile(File path, String write_str) throws Exception {
        FileOutputStream fout = new FileOutputStream(path);
        byte[] bytes = write_str.getBytes();
        fout.write(bytes);
        fout.close();
    }


    //读SD中的文件
    public static String readFileSdcardFile(File path) throws Exception {
        String res = "";
        FileInputStream fin = new FileInputStream(path);
        int length = fin.available();
        byte[] buffer = new byte[length];
        fin.read(buffer);
        res = new String(buffer, "UTF-8");
        fin.close();
        return res;
    }

    public static String readMsgFile(File path) throws Exception {
        String res = "";
        FileInputStream fin = new FileInputStream(path);
        int length = fin.available();
        byte[] buffer = new byte[length];
        fin.read(buffer);
        res = new String(buffer, "GBK");
        fin.close();
        return res;
    }
}
